<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace api\api\controller;

use api\api\service\IndexService;
use api\api\service\UserService;
use cmf\controller\RestBaseController;
use think\App;
use think\Db;

class IndexController extends RestBaseController
{

    function getphone($adcode)
    {
        $phone = Db::name('pricing_tactics')->where('county_id', $adcode)->value('phone');

        if ($phone) {
            $this->success("设置成功!", $phone);
        }
        $this->error("设置失败", '968888');

    }

    /**
     * @api {post} allow_push_set 用户推送设置是否允许.
     * @apiGroup user
     *
     * @apiParam {Int} token 用户token.
     *
     * @apiSuccess {String} code 返回值.
     * @apiSuccess {String} msg  返回说明.
     * @apiSuccess {String} data  返回数据.
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *           "code": 1,
     *           "msg": '获取成功'
     *         "data": ""
     *     }
     *
     * @apiError {String} code 返回值.
     * @apiError {String} msg  返回说明.
     *
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *         "code": 0,
     *           "msg": '获取失败'
     *     }
     */
    public function allow_push_set($allow_push)
    {
        $userid = $this->getUserId();
        $userService = new UserService();

        $ret_ = $userService->setuserparm($userid, 'allow_push', $allow_push);
        if ($ret_) {
            $this->success("设置成功!", $ret_);
        }
        $this->error("设置失败");
    }

    /**
     * @api {post} user_nickname_set 用户设置昵称.
     * @apiGroup user
     *
     * @apiParam {Int} token 用户token.
     *
     * @apiSuccess {String} code 返回值.
     * @apiSuccess {String} msg  返回说明.
     * @apiSuccess {String} data  返回数据.
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *           "code": 1,
     *           "msg": '获取成功'
     *         "data": ""
     *     }
     *
     * @apiError {String} code 返回值.
     * @apiError {String} msg  返回说明.
     *
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *         "code": 0,
     *           "msg": '获取失败'
     *     }
     */
    public function user_nickname_set($user_nickname)
    {
        $userid = $this->getUserId();
        $userService = new UserService();

        $ret_ = $userService->setuserparm($userid, 'user_nickname', $user_nickname);
        if ($ret_) {
            $this->success("设置成功!", $ret_);
        }
        $this->error("设置失败");
    }

    /**
     * 标准日期格式化为中文汉字日期。
     * 例：'2014-12-26' → '二〇一四 年 十二 月 二十六 日'；
     *    '2015-04-07' → '二〇一五 年 四 月 七 日 '
     * @param string $ymd 年月日字符串，必须是strtotime能接受的格式。具体格式要求请参考strtotime。
     * @param string $zero 年份中的'0'的表达方式，缺省为'〇'，也可以根据需要传入'零'之类的。
     * @param boolean $leadSp 年月日是否需要空格分隔。
     *      TRUE的情况： '二〇一四 年 十二 月 二十六 日'；
     *      FALSE的情况：'二〇一四年十二月二十六日'。
     * @return string 格式化之后的日期（汉字表达）
     */
    public function toYmdFullHanzi($ymd, $zero = '〇', $leadSp = FALSE)
    {
        $dt = strtotime($ymd);
        $y = date('Y', $dt);
        $m = date('n', $dt);
        $d = date('j', $dt);
        $y1 = substr($y, 0, 1);
        $y2 = substr($y, 1, 1);
        $y3 = substr($y, 2, 1);
        $y4 = substr($y, 3, 1);
        $hans = array(0 => $zero, 1 => '一', 2 => '二', 3 => '三', 4 => '四', 5 => '五', 6 => '六', 7 => '七',
            8 => '八', 9 => '九', 10 => '十', 11 => '十一', 12 => '十二', 13 => '十三', 14 => '十四', 15 => '十五',
            16 => '十六', 17 => '十七', 18 => '十八', 19 => '十九', 20 => '二十', 21 => '二十一', 22 => '二十二',
            23 => '二十三', 24 => '二十四', 25 => '二十五', 26 => '二十六', 27 => '二十七', 28 => '二十八',
            29 => '二十九', 30 => '三十', 31 => '三十一');
        return $hans[$y1] . $hans[$y2] . $hans[$y3] . $hans[$y4] . ($leadSp ? ' 年 ' : '年') .
            $hans[$m] . ($leadSp ? ' 月 ' : '月') .
            $hans[$d] . ($leadSp ? ' 日' : '日');
    }

    function location_api()
    {
        $province_id = $this->request->param('province_id/a');
        $ret = Db::name('areas')->where(array('parent_id' => $province_id))->order('id asc')->select();
        if ($ret) {
            $this->success('获取成功', $ret);
        } else {
            $this->error('获取失败');
        }
    }

    /**
     * @api {post} update_avatar 用户设置头像.
     * @apiGroup user
     *
     * @apiParam {Int} token 用户token.
     *
     * @apiSuccess {String} code 返回值.
     * @apiSuccess {String} msg  返回说明.
     * @apiSuccess {String} data  返回数据.
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *           "code": 1,
     *           "msg": '获取成功'
     *         "data": ""
     *     }
     *
     * @apiError {String} code 返回值.
     * @apiError {String} msg  返回说明.
     *
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *         "code": 0,
     *           "msg": '获取失败'
     *     }
     */
    public function update_avatar($avatar)
    {
        $userid = $this->getUserId();
        $userService = new UserService();

        $ret_ = $userService->setuserparm($userid, 'avatar', $avatar);
        if ($ret_) {
            $this->success("头像修改成功!", $ret_);
        }
        $this->error("头像修改失败");
    }

    /**
     * @api {post} upload_oneimg 图片上传.
     * @apiGroup user
     *
     * @apiParam {Int} token 用户token.
     *
     * @apiSuccess {String} code 返回值.
     * @apiSuccess {String} msg  返回说明.
     * @apiSuccess {String} data  返回数据.
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *           "code": 1,
     *           "msg": '获取成功'
     *         "data": ""
     *     }
     *
     * @apiError {String} code 返回值.
     * @apiError {String} msg  返回说明.
     *
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *         "code": 0,
     *           "msg": '获取失败'
     *     }
     */
    public function upload_oneimg()
    {
        // 获取表单上传文件 例如上传了001.jpg
        $file = request()->file('file');
        // 移动到框架应用根目录/public/upload/ 目录下
        $info = $file->move(WEB_ROOT . 'upload');
        if ($info) {
            $path = $info->getSaveName();
            if (empty($path)) {
                $this->error("上传失败!");
            }
            $path = str_replace("\\", "/", $path);
            $this->success("上传成功", $path);
        }
    }

    /**
     * @api {post} tactics_get 获取城市策略.
     * @apiGroup user
     *
     * @apiParam {Int} token 用户token.
     *
     * @apiSuccess {String} code 返回值.
     * @apiSuccess {String} msg  返回说明.
     * @apiSuccess {String} data  返回数据.
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *           "code": 1,
     *           "msg": '获取成功'
     *         "data": ""
     *     }
     *
     * @apiError {String} code 返回值.
     * @apiError {String} msg  返回说明.
     *
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *         "code": 0,
     *           "msg": '获取失败'
     *     }
     */
    public function tactics_get($info, $adcode, $lon, $lat, $classd)
    {
        $indexService = new IndexService();
        $ret_ = $indexService->gettactics($adcode, $info, $classd, $lon, $lat);
        if ($ret_ === false) {
            $this->error("获取失败");
        }
        $this->success("获取成功", $ret_);
    }

    /**
     * @api {post} order 用户订单提交.
     * @apiGroup user
     *
     * @apiParam {Int} token 用户token.
     * @apiParam {object} param 起始点经纬度地址数据.
     * @apiParam {decimal} order_amount 订单金额.
     * @apiParam {String} reservation_time 乘车时间.
     * @apiParam {Int} adcode 区域ID.
     * @apiParam {String} remarks 订单备注.
     * @apiParam {Int} total_mileage 总里程.
     * @apiParam {Int} order_type 订单类型子类.
     * @apiParam {Int} ride 乘车人数.
     * @apiParam {String} phone 用户电话.
     * @apiParam {String} phoneself 用户称呼.
     * @apiParam {Int} isother 是否为他人叫车.
     *
     * @apiSuccess {String} code 返回值.
     * @apiSuccess {String} msg  返回说明.
     * @apiSuccess {String} data  返回数据.
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *           "code": 1,
     *           "msg": '提交成功'
     *         "data": ""
     *     }
     *
     * @apiError {String} code 返回值.
     * @apiError {String} msg  返回说明.
     *
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *         "code": 0,
     *           "msg": '提交失败'
     *     }
     */
    public function order($param, $order_amount, $reservation_time, $adcode, $remarks, $total_mileage, $order_type, $ride, $phone, $phoneself, $isother, $initindex, $contain1, $contain2, $cd1money, $cd2money, $linecost, $addprice, $addpriceinfo)
    {
//        $good_type_sm=$this->request->param('good_type_sm','','intval');
        $good_type_sm = input('good_type_sm', '');

        $userid = $this->getUserId();
        $param = json_decode($param, true);
        $data = [];

        // if(!$reservation_time){
        // 	$reservation_time = date("Y-m-d H:i",time());
        // }
        $indexService = new IndexService();
        $ret_ = $indexService->suborder($userid);
        $data['order_number'] = 'J' . $this->_createOrderSN();
        $data['type'] = $initindex;
        $data['user_id'] = $userid;
        $data['order_amount'] = $order_amount;
        $data['real_amount'] = $order_amount;
        $data['reservation_time'] = $reservation_time;
        $data['good_type_sm'] = $good_type_sm;
        if ($reservation_time) {
            $data['is_reservation'] = 1;
            //预约时间戳
            $yuyue = strtotime($reservation_time);
            //预约派单时间
            $yuyuepaidan = $yuyue - (40 * 60);
            $quxiao = $yuyue - (15 * 60);
            //预约派送时间大于当前时间 可以达到时间派单  否则及时派单
            if ($yuyuepaidan > time()) {
                $data['send_order_time'] = $yuyuepaidan;
                $data['expire_time'] = $yuyue - (15 * 60);
            } else {
                $data['send_order_time'] = time();
                //大于十五分钟
                if ($yuyuepaidan > time()) {
                    $data['expire_time'] = $yuyue - (15 * 60);
                } else {
                    //小于十五分钟
                    $data['expire_time'] = time() + 14 * 60;
                }

            }
        } else {
            $data['send_order_time'] = time();
            $data['reservation_time'] = date('Y-m-d H:i', time());
            $reservation_time = date('Y-m-d H:i', time());
        }
        $data['adcode'] = $adcode;
        $data['mobile'] = $phone;
        $data['start_district'] = $param['district'];
        $data['start_address'] = $param['address'];
        $data['start_lon'] = $param['startLon'];
        $data['start_lat'] = $param['startLat'];
        $data['end_district'] = $param['districtend'];
        $data['end_address'] = $param['addressend'];
        $data['end_lon'] = $param['endLon'];
        $data['end_lat'] = $param['endLat'];
        $data['order_time'] = time();
        if (array_key_exists('expire_time', $data) && $data['expire_time']) {

        } else {
            $data['expire_time'] = time() + 14 * 60;
        }

        $data['is_pay_first'] = $ret_;
        $data['remark'] = $remarks;
        $data['total_mileage'] = $total_mileage;
        $data['order_type'] = $order_type;
        $data['isother'] = $isother;
        $data['isname'] = $phoneself;
        $data['contain1'] = $contain1;
        $data['cd1money'] = $cd1money;
        $data['contain2'] = $contain2;
        $data['cd2money'] = $cd2money;
        $data['ride'] = $ride;
        $data['linecost'] = $linecost;
        $data['addprice'] = $addprice;
        $data['addpriceinfo'] = $addpriceinfo;
        if (!empty($param['id'])) {
            $data['line_id'] = $param['id'];
        }


        if ($initindex == 1) {//如果是跨城类型判断下单时间
            $reservation_time = strtotime($reservation_time);
            $reservation_time = date('Y-m-d H:i', $reservation_time);
            $_line_money = $indexService->check_time_($reservation_time);
            if (!$_line_money) {
                $this->error("此时间段请选择包车");
            }
        }
        if ($order_type == 1 || $order_type == 2) {
            $distance_ = $indexService->line_distance($param);
            $distance = 0;
            if ($distance_['status'] == 0) {
                $distance = $distance_['result'][0]['distance']['value'];
                $distance = number_format($distance / 1000, 2);//格式化为公里保留两位小数
            }
            //计算区域策略价格=======================================
            $KiloMoney_ = $indexService->distance_train_money($adcode, $distance);
            //区域策略价格===========================================结束

            $markupprice_ = $indexService->line_train_order_price($adcode, $order_type);//临时加价
            $allprice = $KiloMoney_['totalPrice'] + $markupprice_['addprice'];
            if (round($order_amount, 2) != round($allprice, 2)) {
                $this->error("订单金额计算有误，请重新下单");
            }
            $info = $indexService->insert_order_data($data);
        } else if ($order_type == 3) {
            $distance_ = $indexService->line_distance($param);
            $distance = 0;
            if ($distance_['status'] == 0) {
                $distance = $distance_['result'][0]['distance']['value'];
                $distance = number_format($distance / 1000, 2);//格式化为公里保留两位小数
            }
            //计算区域策略价格=======================================
            $KiloMoney_ = $indexService->distance_train_money3($adcode, $distance);
            //区域策略价格===========================================结束

            $markupprice_ = $indexService->line_train_order_price($adcode, $order_type);//临时加价
            $allprice = $KiloMoney_['totalPrice'] + $markupprice_['addprice'];
            if (round($order_amount, 2) != round($allprice, 2)) {
                $this->error("订单金额计算有误，请重新下单");
            }
            $info = $indexService->insert_order_data($data);
        } else if ($order_type == 4) {
            $distance_ = $indexService->line_distance($param);
            $distance = 0;
            if ($distance_['status'] == 0) {
                $distance = $distance_['result'][0]['distance']['value'];
                $distance = number_format($distance / 1000, 2);//格式化为公里保留两位小数
            }
            //计算区域策略价格=======================================
            $KiloMoney_ = $indexService->distance_train_money4($adcode, $distance);
            //区域策略价格===========================================结束

            $markupprice_ = $indexService->line_train_order_price($adcode, $order_type);//临时加价
            $allprice = $KiloMoney_['totalPrice'] + $markupprice_['addprice'];
            if (round($order_amount, 2) != round($allprice, 2)) {
                $this->error("订单金额计算有误，请重新下单");
            }
            $info = $indexService->insert_order_data($data);
        } else if ($order_type == 10) {//如果是拼车计费方式
            $amounts = [];
            $amounts['contain1'] = 0.00;
            $amounts['contain2'] = 0.00;
            //获取订单专线价格
            $_line_money = $indexService->get_line_money($data['line_id'], $data['ride']);
            $amounts['lineprice'] = $_line_money['allregionprice'];//乘客人数专线费用
            //获取临时加价
            $markup_price = $indexService->line_markup_price($data['adcode'], $data['order_type'], $data['ride']);
            $amounts['addprice'] = $markup_price['addprice'];//临时加价
            $amounts['addpricetitle'] = $markup_price['addtimes'];//临时加价原因
            //获取是否超出费用
            if ($contain1) {
                $_distance_money = $indexService->get_distance_money($data['line_id'], 1, $data['start_lon'], $data['start_lat']);
                $amounts['contain1'] = $_distance_money;
            }
            if ($contain2) {
                $_distance_money = $indexService->get_distance_money($data['line_id'], '', $data['end_lon'], $data['end_lat']);
                $amounts['contain2'] = $_distance_money;
            }
            $allprice = $amounts['lineprice'] + $amounts['addprice'] + $amounts['contain1'] + $amounts['contain2'];
            if (round($order_amount, 2) != round($allprice, 2)) {
                $this->error("订单金额计算有误，请重新下单");
            }
            $info = $indexService->insert_order_data($data);
        } else if ($order_type == 11) {
            $amounts = [];
            $amounts['contain1'] = 0.00;
            $amounts['contain2'] = 0.00;
            //获取订单专线价格
            $amounts['lineprice'] = $linecost;//专线费用
            //获取临时加价
            $markup_price = $indexService->line_markup_price($data['adcode'], $data['order_type'], $data['ride']);
            $amounts['addprice'] = $markup_price['addprice'];//临时加价
            $amounts['addpricetitle'] = $markup_price['addtimes'];//临时加价原因
            //获取是否超出费用
            if ($contain1) {
                $_distance_money = $indexService->get_distance_money($data['line_id'], 1, $data['start_lon'], $data['start_lat']);
                $amounts['contain1'] = $_distance_money;
            }
            if ($contain2) {
                $_distance_money = $indexService->get_distance_money($data['line_id'], '', $data['end_lon'], $data['end_lat']);
                $amounts['contain2'] = $_distance_money;
            }
            $allprice = $amounts['lineprice'] + $amounts['addprice'] + $amounts['contain1'] + $amounts['contain2'];
            if (round($order_amount, 2) != round($allprice, 2)) {
                $this->error("订单金额计算有误，请重新下单");
            }
            $info = $indexService->insert_order_data($data);
        } else if ($order_type == 12 || $order_type == 13) {
            $amounts = [];
            $amounts['contain1'] = 0.00;
            $amounts['contain2'] = 0.00;

            //获取订单专线价格
            $_line_money = $indexService->pickupamount_money($adcode);
            if (!$_line_money) {
                $this->error("下单失败");
            }
            //获取订单专线价格
            $amounts['lineprice'] = $_line_money;//专线费用
            //获取临时加价
            $markup_price = $indexService->line_markup_price($data['adcode'], $data['order_type'], $data['ride']);
            $amounts['addprice'] = $markup_price['addprice'];//临时加价
            $amounts['addpricetitle'] = $markup_price['addtimes'];//临时加价原因
            //获取是否超出费用
            if ($contain1) {
                $_distance_money = $indexService->get_distance_money($data['line_id'], 1, $data['start_lon'], $data['start_lat']);
                $amounts['contain1'] = $_distance_money;
            }
            if ($contain2) {
                $_distance_money = $indexService->get_distance_money($data['line_id'], '', $data['end_lon'], $data['end_lat']);
                $amounts['contain2'] = $_distance_money;
            }
            $allprice = $amounts['lineprice'] + $amounts['addprice'] + $amounts['contain1'] + $amounts['contain2'];
            if (round($order_amount, 2) != round($allprice, 2)) {
                $this->error("订单金额计算有误，请重新下单");
            }
            $info = $indexService->insert_order_data($data);
        } else if ($order_type == 14 || $order_type == 15) {
            //快件参数
            // if(!empty(input('goods_type'))){
            // 	$data['goods_type']          = $goods_type;
            // }
            $data['goods_type'] = input('goods_type');
            $data['send_mobile'] = input('send_mobile');
            $data['send_name'] = input('send_name');
            $data['reci_mobile'] = input('reci_mobile');
            $data['reci_name'] = input('reci_name');
            $info = $indexService->insert_order_data($data);
        }


        $fordata = [];
        $fordata['orderid'] = $info;
        $fordata['pay'] = false;
        $fordata['order_number'] = $data['order_number'];
        if ($ret_ && $initindex != 3) {//为真则先付费
            $fordata['pay'] = $ret_;
            $this->success("获取成功", $fordata);
        }
        order_auto_designate($info);
        $this->success("获取成功", $fordata);
    }

    // 生成订单号
    private function _createOrderSN()
    {
        return date('YmdHis', time()) . '' . $this->randNumber();
    }

    /**
     * 获取随机位数数字
     * @param integer $len 长度
     * @return string
     */
    public function randNumber($len = 4)
    {
        $chars = str_repeat('0123456789', 10);
        $chars = str_shuffle($chars);
        $str = substr($chars, 0, $len);
        return $str;
    }

    /**
     * @api {post} getordermoney 用户获取订单价格.
     * @apiGroup user
     *
     * @apiParam {Int} token 用户token.
     *
     * @apiSuccess {String} code 返回值.
     * @apiSuccess {String} msg  返回说明.
     * @apiSuccess {String} data  返回数据.
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *           "code": 1,
     *           "msg": '提交成功'
     *         "data": ""
     *     }
     *
     * @apiError {String} code 返回值.
     * @apiError {String} msg  返回说明.
     *
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *         "code": 0,
     *           "msg": '提交失败'
     *     }
     */
    public function getordermoney($adcode, $mileage, $param)
    {
        $param = json_decode($param, true);
        $indexService = new IndexService();
        //判断距离差=======================================
        $data = $indexService->line_distance($param);
        if ($data['status'] != 0) {
            $this->error("距离计算错误");
        }
        $distance = intval($data['result'][0]['distance']['value'] / 1000);
        if (intval($mileage) != $distance) {
            $this->error("距离计算错误");
        }
        //判断距离相差=====================================结束
        //判断是否超出区域-返回最终价格=================================
        $data = $indexService->line_contain($param);
        //判断是否超出区域=================================结束
        $this->success("获取成功!", $data);
    }

    /**
     * @api {post} getdistancemoney 用户获取超出区域距离与超出价格.
     * @apiGroup user
     *
     * @apiParam {Int} token 用户token.
     *
     * @apiSuccess {String} code 返回值.
     * @apiSuccess {String} msg  返回说明.
     * @apiSuccess {String} data  返回数据.
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *           "code": 1,
     *           "msg": '提交成功'
     *         "data": ""
     *     }
     *
     * @apiError {String} code 返回值.
     * @apiError {String} msg  返回说明.
     *
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *         "code": 0,
     *           "msg": '提交失败'
     *     }
     */
    public function getdistancemoney($adcode, $lon, $lat, $locationparam)
    {
        $locationparam = json_decode($locationparam, true);
        $datas = [];
        $param['startLon'] = $lon;
        $param['startLat'] = $lat;

        $indexService = new IndexService();
        foreach ($locationparam as $k => $v) {
            $param['endLon'] = $v['lon'];
            $param['endLat'] = $v['lat'];
            $distance_ = $indexService->line_distance($param);
            if ($distance_['status'] == 0) {
                array_push($datas, $distance_['result'][0]['distance']['value']);
            }
        }
        $distance = min($datas);//获取最短距离
        $distance = number_format($distance / 1000, 2);//格式化为公里保留两位小数

        //计算区域策略价格=======================================
        $KiloMoney_ = $indexService->distance_money($adcode, $distance);
        //区域策略价格===========================================结束

        if ($distance > 10) {
            $this->success("地址超出区域范围!,计费较高,建议更换专线", $KiloMoney_['totalPrice']);
        }
        $this->success("", $KiloMoney_['totalPrice']);
    }

    /**
     * @api {post} getmarkupprice 用户获取夜间加价及临时加价价格.
     * @apiGroup user
     *
     * @apiParam {Int} linecost 专线价格.
     * @apiParam {Int} ride 乘车人数.
     * @apiParam {Int} classd 类型.
     * @apiParam {Int} adcode 区域ID.
     *
     * @apiSuccess {String} code 返回值.
     * @apiSuccess {String} msg  返回说明.
     * @apiSuccess {String} data  返回数据.
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *           "code": 1,
     *           "msg": '获取成功'
     *         "data": ""
     *     }
     *
     * @apiError {String} code 返回值.
     * @apiError {String} msg  返回说明.
     *
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *         "code": 0,
     *           "msg": '获取失败'
     *     }
     */
    public function getmarkupprice($adcode, $classd, $ride)
    {
        $indexService = new IndexService();
        $markupprice_ = $indexService->line_markup_price($adcode, $classd, $ride);
        $this->success("获取成功", $markupprice_);
    }

    public function gettrainorderprice($adcode, $classd, $param)
    {
        $paramdata = json_decode($param, true);
        $datas = [];
        $locationparam['startLon'] = $paramdata['startLon'];
        $locationparam['startLat'] = $paramdata['startLat'];
        $locationparam['endLon'] = $paramdata['endLon'];
        $locationparam['endLat'] = $paramdata['endLat'];
        $indexService = new IndexService();
        $distance_ = $indexService->line_distance($locationparam);
        $distance = 0;
        if ($distance_['status'] == 0) {
            $distance = $distance_['result'][0]['distance']['value'];
            $distance = number_format($distance / 1000, 2);//格式化为公里保留两位小数
        }

        //计算区域策略价格=======================================
        if ($classd == 1 || $classd == 2) {
            $KiloMoney_ = $indexService->distance_train_money($adcode, $distance);
        } else if ($classd == 3) {
            $KiloMoney_ = $indexService->distance_train_money3($adcode, $distance);
        } else {//代驾
            $KiloMoney_ = $indexService->distance_train_money4($adcode, $distance);
        }
        //区域策略价格===========================================结束
//        $this->success("获取成功",$KiloMoney_);
        $markupprice_ = $indexService->line_train_order_price($adcode, $classd);//临时加价

        $datas['addprice'] = $markupprice_['addprice'];
        $datas['addtimes'] = $markupprice_['addtimes'];
        $datas['discount'] = $KiloMoney_['totalPrice'];

        $this->success("获取成功", $datas);
    }

    /**
     * @api {post} getorderstatus 用户获取订单状态.
     * @apiGroup user
     *
     * @apiParam {Int} $orderid 订单ID.
     *
     * @apiSuccess {String} code 返回值.
     * @apiSuccess {String} msg  返回说明.
     * @apiSuccess {String} data  返回数据.
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *           "code": 1,
     *           "msg": '获取成功'
     *         "data": ""
     *     }
     *
     * @apiError {String} code 返回值.
     * @apiError {String} msg  返回说明.
     *
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *         "code": 0,
     *           "msg": '获取失败'
     *     }
     */
    public function getorderstatus($orderid, $source = 0)
    {
        $indexService = new IndexService();
        $order_status_ = $indexService->get_order_status($orderid);
        if ($order_status_) {
            if ($order_status_['driver_id']) {
                $order_status_['driver_mobile'] = Db::name('driver_user')->where('id', $order_status_['driver_id'])->value('mobile');
            }
            if (!empty($order_status_['avatar'])) {
                $order_status_['avatar'] = cmf_get_asset_url($order_status_['avatar']);
            } else {
                $order_status_['avatar'] = '';
            }
            $order_status_['prize'] = [];

            //根据source 状态以及订单可抽奖次数   信息
            if ($source == 1 && $order_status_['prize_number'] && $order_status_['line_id']) {
                //查询 专线是否能抽奖相关信息
                $line_info = Db::name('region_line')->where('id', $order_status_['line_id'])->find();

                if (!empty($line_info) && $line_info['prize_flag']) {

                    $order_status_['prize'] = json_decode($line_info['prize_json'], true);

                }
            }

            $this->success("获取成功", $order_status_);
        }
        $this->error("获取失败");
    }

    public function update_order_prize($orderid, $prize_amount = 0)
    {
        if (empty($orderid)) {
            $this->error("参数错误");
        }
        $order_info = Db::name('order')->where('order_id', $orderid)->find();
        if (floatval($prize_amount) >= floatval($order_info['real_amount'])) {
            $update_arr['real_amount'] = 0.01;
        } else {
            $update_arr['real_amount'] = floatval($order_info['real_amount']) - floatval($prize_amount);
        }
        $update_arr['prize_number'] = 0;
        $update_arr['prize_amount'] = $prize_amount;

        $res = Db::name('order')->where('order_id', $orderid)->update($update_arr);

        if ($res) {
            $this->success("订单金额更新成功");
        } else {
            $this->error("更新失败");
        }

    }

    /**
     * @api {post} cancleOrderOption 取消订单操作.
     * @apiGroup user
     *
     * @apiParam {String} order_number 订单号 必填
     *
     * @apiSuccess {String} code 返回值.
     * @apiSuccess {String} msg  返回说明.
     * @apiSuccess {String} data  返回数据.
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *           "code": 1,
     *           "msg": '获取成功'
     *         "data": ""
     *     }
     *
     * @apiError {String} code 返回值.
     * @apiError {String} msg  返回说明.
     *
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *         "code": 0,
     *           "msg": '获取失败'
     *     }
     */
    public function cancleOrderOption($order_number, $cancel_party)
    {
        $indexService = new IndexService();
        if (!$order_number)
            $this->error("参数为空");

        //取得订单数据
        if ($cancel_party == 1) {//取消方是用户
            $userid = $this->getUserId();
            $order_obj_ = $indexService->get_order_obj($order_number, $userid, 'user_id');
        } else if ($cancel_party == 2) {
            $userid = $this->getDriverId();
            $order_obj_ = $indexService->get_order_obj($order_number, $userid, 'driver_id');
        }
        $status = $order_obj_['status'];
        $order_id = $order_obj_['order_id'];
        $pay_status = $order_obj_['pay_status'];

        Db::startTrans(); //开启事务
        try {
            if (!$order_obj_)
                $this->error("订单号有误");
            if ($status > 2)
                $this->error("订单状态有误");
            switch ($status) {
                case 1:
                    $update_ = $indexService->update_order_obj($order_id, 'status', 6);
                    $remark_msg = '您取消了订单(' . $order_number . ')';
                    if ($pay_status == 1) {
                        $refund_ = $indexService->cancle_refund($userid, $order_obj_);//退款
                        //消息推送
                        $refund_ = $indexService->jpush_send_user(1, '您的订单(' . $order_number . ')取消成功', $userid);
                    }
                    break;
                case 2:
                    $update_ = $indexService->update_order_obj($order_id, 'status', 6);
                    $up_cancle_ = $indexService->up_user_param($userid, 'cancle_num', 1);
                    $remark_msg = '您取消了订单(' . $order_number . ')';
                    if ($pay_status == 1) {
                        $refund_ = $indexService->cancle_refund($userid, $order_obj_);//退款
                        //消息推送
                        $refund_ = $indexService->jpush_send_user(1, '您的订单(' . $order_number . ')取消成功', $userid);
                        //司机消息推送
                        $refund_ = $indexService->jpush_send_driver(2, '订单取消，单号(' . $order_number . ')用户已取消', $order_obj_['driver_id']);
                    }
                    break;
                default:
                    $this->error("订单取消失败");
                    break;
            }
            //取消日志
            $msg_ret = create_user_message(1, $userid, '取消订单', $remark_msg, $remark_msg);

            // 提交事务
            Db::commit();
        } catch (\Exception $e) {
            // 回滚事务
            Db::rollback();
            $this->error("订单取消失败");
        }
        $this->success("订单取消成功");
    }

    public function userRegistrationID($registrationId)
    {
        $userid = $this->getUserId();
        $indexService = new IndexService();
        $_registration = $indexService->save_registration($userid, $registrationId);
        if ($_registration) {
            $this->success("推送绑定成功");
        } else {
            $this->error("推送绑定失败!");
        }
    }

    /**
     * @api {post} getOrderpaystatus 支付完成复查订单支付状态.
     * @apiGroup user
     *
     * @apiParam {String} order_number 订单号 必填
     *
     * @apiSuccess {String} code 返回值.
     * @apiSuccess {String} msg  返回说明.
     * @apiSuccess {String} data  返回数据.
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *           "code": 1,
     *           "msg": '获取成功'
     *         "data": ""
     *     }
     *
     * @apiError {String} code 返回值.
     * @apiError {String} msg  返回说明.
     *
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *         "code": 0,
     *           "msg": '获取失败'
     *     }
     */
    public function getOrderpaystatus($ordernumber, $paytype)
    {
        $userid = $this->getUserId();
        $indexService = new IndexService();
        $where['order_number'] = $ordernumber;
        $result = $indexService->get_order_obj($ordernumber, $userid, 'user_id');
        $fee = $result['real_amount'];
        if ($result && $result['pay_status'] == 0) {

            //开启事务
            Db::startTrans();
            //支付完成逻辑
            $data_pay['pay_status'] = $paytype;
            $data_pay['pay_method'] = 1;
            //更新订单表支付数据和状态
            $ret_pay = $indexService->update_order_obj_array($result['order_id'], $data_pay);
            $remark_msg = '支付订单' . $ordernumber . $fee . '元';
            $balanceLog = userbalanceLog($userid, $paytype, 2, $fee, '', $remark_msg, $result['order_id'], '');
            if ($result['status'] > 1) {
                //消息推送
                $refund_ = $indexService->jpush_send_user(1, '支付完成,订单(' . $ordernumber . ')已支付', $userid);
            }
            if (!$ret_pay || !$balanceLog) {
                Db::rollback();
                $this->error("支付失败");
            }

            Db::commit();
            $this->success("支付成功!");
        }
        $this->success("支付完成!");
    }

    /**
     * @api {post} getOrderpaystatus 用户评价司机.
     * @apiGroup user
     *
     * @apiParam {String} order_number 订单号 必填
     *
     * @apiSuccess {String} code 返回值.
     * @apiSuccess {String} msg  返回说明.
     * @apiSuccess {String} data  返回数据.
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *           "code": 1,
     *           "msg": '获取成功'
     *         "data": ""
     *     }
     *
     * @apiError {String} code 返回值.
     * @apiError {String} msg  返回说明.
     *
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *         "code": 0,
     *           "msg": '获取失败'
     *     }
     */
    public function evaluate($order_id, $text, $value)
    {
        $userid = $this->getUserId();
        $indexService = new IndexService();

        //开启事务
        Db::startTrans();

        $evaluate = $indexService->evaluate_user($userid, $order_id, $text, $value);
        if (!$evaluate) {
            $this->error("评价失败");
        }

        $this->success("评价成功!");
    }

    /**
     * @api {post} gethelplist 获取用户帮助.
     * @apiGroup user
     *
     * @apiParam {Int} type 帮助类型.
     *
     * @apiSuccess {String} code 返回值.
     * @apiSuccess {String} msg  返回说明.
     * @apiSuccess {String} data  返回数据.
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *           "code": 1,
     *           "msg": '获取成功'
     *         "data": ""
     *     }
     *
     * @apiError {String} code 返回值.
     * @apiError {String} msg  返回说明.
     *
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *         "code": 0,
     *           "msg": '获取失败'
     *     }
     */
    public function gethelplist($type)
    {
        $indexService = new IndexService();
        $data = $indexService->get_help_list($type);
        if ($data) {
            $this->success("获取成功!", $data);
        } else {
            $this->error("获取失败");
        }
    }

    /**
     * @api {post} gethelpdateils 获取用户帮助详情.
     * @apiGroup user
     *
     * @apiParam {Int} id 帮助ID.
     *
     * @apiSuccess {String} code 返回值.
     * @apiSuccess {String} msg  返回说明.
     * @apiSuccess {String} data  返回数据.
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *           "code": 1,
     *           "msg": '获取成功'
     *         "data": ""
     *     }
     *
     * @apiError {String} code 返回值.
     * @apiError {String} msg  返回说明.
     *
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *         "code": 0,
     *           "msg": '获取失败'
     *     }
     */
    public function gethelpdateils($id)
    {
        $indexService = new IndexService();
        $data = $indexService->get_help_dateils($id);
        if ($data) {
            $data['content'] = htmlspecialchars_decode($data['content']);
            $this->success("获取成功!", $data);
        } else {
            $this->error("获取失败");
        }
    }


    /**
     * @api {post} get_slider_list 获取轮播.
     * @apiGroup index
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *
     *  {
     *      "Code": 1,
     *   "msg": '更新成功'
     *      "data": ""
     *  }
     **/

    public function get_slider_list()
    {
        $where = array(
            'slide_id' => 1,
            'status' => 1
        );
        $indexService = new IndexService();
        $slider_list = $indexService->get_slider_list($where);
        if ($slider_list->isEmpty()) {
            $this->error("加载完成");
        }
        $this->success("获取成功!", $slider_list);
    }

    /**
     * @api {post} get_zixun_types 获取分类栏目组.
     * @apiGroup index
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *
     *  {
     *      "Code": 1,
     *   "msg": '更新成功'
     *      "data": ""
     *  }
     **/

    public function get_zixun_types()
    {
        $indexService = new IndexService();

        $zixun_types = $indexService->portal_category_select_order_list_order(array('status' => 1));
        if ($zixun_types->isEmpty()) {
            $this->error("参数错误");
        } else {
            $backarr['zixun_types'] = $zixun_types;
            $items = [];
            foreach ($zixun_types as $k => $val) {
                $items[$k]['title'] = $val['name'];
                $items[$k]['bg'] = '#FFF';
                $items[$k]['bgSelected'] = '#FFF';
            }
            $class_list = $indexService->portal_category_select(array('status' => 1));
            foreach ($class_list as $k => $v) {
                $backarr['portal_categorys'][$v['id']] = $v['name'];
            }
            $backarr['items'] = $items;
            $this->success("获取成功!", $backarr);
        }

    }

    /**
     * @api {post} get_portal_list 根据分类id 分页获取文章列表.
     * @apiGroup index
     *
     * @apiParam {Int} page 当前页数.
     * @apiParam {Int} category 分类id.
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *
     *  {
     *      "Code": 1,
     *   "msg": '更新成功'
     *      "data": ""
     *  }
     **/

    public function get_portal_list()
    {
        $page = input('page');
        $category = input('category');
        $where = array('post.category_id' => $category, 'post.status' => 1, 'portal.post_status' => 1);
        $indexService = new IndexService();
        $data = $indexService->get_portal_by_category_list($where, $page);
        if ($data) {
            $this->success("获取成功!", $data);
        } else {
            $this->error("加载完成");
        }
    }

    /**
     * @api {post} get_portal_detail 获取文章详情
     * @apiGroup index
     *
     * @apiParam {Int} id 文章id.
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *
     *  {
     *      "Code": 1,
     *   "msg": '更新成功'
     *      "data": ""
     *  }
     **/

    public function get_portal_detail()
    {
        $id = input('id');
        $where = array('id' => $id, 'post_status' => 1);
        $indexService = new IndexService();
        $data = $indexService->get_portal_detail($where);
        if ($data) {

            $data['post_content'] = $this->getPostContentAttr($data['post_content']);
            $data['published_time'] = get_data_foamt($data['published_time']);
            $data['thumbnail'] = cmf_get_image_url($data['thumbnail']);
            $data['more'] = $this->getMoreAttr($data['more']);
            $this->success("获取成功!", $data);
        } else {
            $this->error("加载完成");
        }
    }

    /**
     * more 自动转化 自动转换url地址
     * @param $value
     * @return array
     */
    public function getMoreAttr($value)
    {
        $more = json_decode($value, true);
        if (!empty($more['thumbnail'])) {
            $more['thumbnail'] = cmf_get_image_url($more['thumbnail']);
        }

        if (!empty($more['audio'])) {
            $more['audio'] = cmf_get_file_download_url($more['audio']);
        }

        if (!empty($more['video'])) {
            $more['video'] = cmf_get_file_download_url($more['video']);
        }

        if (!empty($more['photos'])) {
            foreach ($more['photos'] as $key => $value) {
                $more['photos'][$key]['url'] = cmf_get_image_url($value['url']);
            }
        }

        if (!empty($more['files'])) {
            foreach ($more['files'] as $key => $value) {
                $more['files'][$key]['url'] = cmf_get_file_download_url($value['url']);
            }
        }
        return $more;
    }

    /**
     * 转换文章内容加载url地址
     * post_content 自动转化
     * @param $value
     * @return string
     */
    public function getPostContentAttr($value)
    {
        return cmf_replace_content_file_url(htmlspecialchars_decode($value));
    }

    /**
     * @api {post} getuserareaid 获取用户定位城市id.
     * @apiGroup user
     *
     * @apiParam {Int} adCode 城市定位县区级id.
     *
     * @apiSuccess {String} code 返回值.
     * @apiSuccess {String} msg  返回说明.
     * @apiSuccess {String} data  返回数据.
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *           "code": 1,
     *           "msg": '获取成功'
     *         "data": ""
     *     }
     *
     * @apiError {String} code 返回值.
     * @apiError {String} msg  返回说明.
     *
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *         "code": 0,
     *           "msg": '获取失败'
     *     }
     */
    public function getuserareaid($adCode, $district)
    {
        if (empty($adCode)) {
            $this->error('定位失败!');
        }
        $where = array('id' => $adCode);
        $where2 = array('name' => $district);
        $indexService = new IndexService();
        $data = $indexService->get_areas_id($where, $where2);
        if ($data) {
            $this->success("获取成功!", $data);
        } else {
            $this->error("获取失败");
        }
    }

    /**
     * @api {post} getuserareaid 获取专线.
     * @apiGroup user
     *
     * @apiParam {Int} adCode 城市定位县区级id.
     *
     * @apiSuccess {String} code 返回值.
     * @apiSuccess {String} msg  返回说明.
     * @apiSuccess {String} data  返回数据.
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *           "code": 1,
     *           "msg": '获取成功'
     *         "data": ""
     *     }
     *
     * @apiError {String} code 返回值.
     * @apiError {String} msg  返回说明.
     *
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *         "code": 0,
     *           "msg": '获取失败'
     *     }
     */
    public function getlinelist($index, $adcode)
    {
        $indexService = new IndexService();
        $data = $indexService->get_line_list($index, $adcode);
        if ($data) {
            $infodata = [];
            foreach ($data as $key => $value) {
                $infodata[$key] = $value;
                $value['star_location'] = str_replace("lng", "lon", $value['star_location']);
                $value['end_location'] = str_replace("lng", "lon", $value['end_location']);
                $infodata[$key]['star_location'] = json_decode($value['star_location']);
                $infodata[$key]['end_location'] = json_decode($value['end_location']);
            }
            $this->success("获取成功!", $infodata);
        } else {
            $this->error("获取失败");
        }
    }

    /**
     * @api {post} getgoodstypelist 获取物品类型列表.
     * @apiGroup user
     *
     * @apiParam {Int} adCode 城市定位县区级id.
     *
     * @apiSuccess {String} code 返回值.
     * @apiSuccess {String} msg  返回说明.
     * @apiSuccess {String} data  返回数据.
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *           "code": 1,
     *           "msg": '获取成功'
     *         "data": ""
     *     }
     *
     * @apiError {String} code 返回值.
     * @apiError {String} msg  返回说明.
     *
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *         "code": 0,
     *           "msg": '获取失败'
     *     }
     */
    public function getgoodstypelist()
    {
        $indexService = new IndexService();
        $data = $indexService->get_goodstype_list();
        if ($data) {

            $this->success("获取成功!", $data);
        } else {
            $this->error("获取失败");
        }
    }

    /**
     * @api {post} upmessages 更新用户系统消息表.
     * @apiGroup user
     *
     * @apiParam {Int} adCode 城市定位县区级id.
     *
     * @apiSuccess {String} code 返回值.
     * @apiSuccess {String} msg  返回说明.
     * @apiSuccess {String} data  返回数据.
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *           "code": 1,
     *           "msg": '获取成功'
     *         "data": ""
     *     }
     *
     * @apiError {String} code 返回值.
     * @apiError {String} msg  返回说明.
     *
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *         "code": 0,
     *           "msg": '获取失败'
     *     }
     */
    public function upmessages($utype)
    {
        $userid = $this->getUserId();
        $indexService = new IndexService();
        $result = $indexService->get_user_messages($userid, $utype);
        if ($result) {
            $this->success("获取成功!", $result);
        } else {
            $this->error("获取失败");
        }
    }

    public function ceshi()
    {
        $indexService = new IndexService();
        $data['startLon'] = '117.64758719661404';
        $data['startLat'] = '35.5121618389484';
        $data['endLon'] = '117.64587143308998';
        $data['endLat'] = '35.51056057926954';
        $data = $indexService->line_distance($data);
        if ($data['status'] == 0) {
            $distance = intval($data['result'][0]['distance']['value'] / 100) / 10;
            $this->success("获取成功!", $distance);
        }
    }

    public function ceshi2()
    {
        $indexService = new IndexService();
        $data = $indexService->line_uu();
        $this->success("获取成功!", $data);
    }

    public function ceshi3()
    {
        $indexService = new IndexService();
        $ret_ = $indexService->suborder(2);
        if ($ret_) {
            $this->success("获取成功!", $ret_);
        }

    }

    public function ceshi4($create_time)
    {
        $strnowtime = strtotime($create_time);
        $system_ = Db::name('system_set')->where('id', 1)->field('timepoint,timepointend')->find();
        $timepoint = $system_['timepoint'];
        $timepointend = $system_['timepointend'];
        $date = substr($create_time, -5, 5);
        if ($date >= $timepoint || $date <= $timepointend) {
            $this->error("获取失败1");
        }

        $this->success("获取成功!", $date);
    }

    public function jpush_send()
    {
        $param = [
            'type' => 2,
            'registration_id' => '1a0018970adee39d3c7',
            'msg' => '你好'
        ];
        $res = hook_one('jpush_send', $param);
    }

    /*
    *根据条件推送消息
    */
    public function jpush_send_driver($type, $remark_msg, $driver_id)
    {
        $result = Db::name('driver_user')->where('id', $driver_id)->field('jpush_id')->find();
        $param = [
            'type' => $type,
            'registration_id' => $result['jpush_id'],
            'msg' => $remark_msg
        ];
        $res = hook_one('jpush_send', $param);

        $this->success("获取成功!", $res);
    }

    public function ceshi5()
    {
//		$where['user_type'] = 2;
//		$where['user_status'] = 1;
//		$user_jpush_ids = Db::name("user")->where($where)->where('jpush_id','not null')->field('jpush_id')->select();
//		$data = $this->reduceArray($user_jpush_ids);
//		$param = [
//			'type' => 1,
//			'registration_id' => $data,
//			'msg' => '您有新的系统消息,请查看'
//		];
//		$res = hook_one('jpush_send', $param);
//		$this->success('推送完成',$data);

        echo strtotime('2019-8-15 9:33');
    }

    private function reduceArray($array)
    {
        $return = [];
        array_walk_recursive($array, function ($x) use (&$return) {
            $return[] = $x;
        });
        return $return;
    }

    /**
     * @api {post} get_zixun_types 获取分类栏目组新版  固定前三.
     * @apiGroup index
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *
     *  {
     *      "Code": 1,
     *   "msg": '更新成功'
     *      "data": ""
     *  }
     **/

    public function get_banner_type()
    {
        $type = input('type');
        if (!$type) {
            $this->error("参数错误");
        }

        $where = array('status' => 1, 'delete_time' => 0, 'type' => $type);

        $banner_types = Db::name('banner_category')->where($where)->order('list_order desc')->select()->toArray();

        if (count($banner_types) < 1) {
            $this->error("参数错误");
        } else {
//            $backarr['zixun_types'] = $banner_types;
            $items = [];
            foreach ($banner_types as $k => $val) {
                $items[$k]['name'] = $val['name'];

                $moreinfo = $this->getMoreAttr($val['more']);
                $items[$k]['path'] = $moreinfo['thumbnail'];
                $items[$k]['url_type'] = $val['url_type'];
                $items[$k]['url'] = $val['url'];


            }
//            $class_list =  Db::name('banner_category')->where($where)->order('list_order desc')->select()->toArray();
//
////            $class_list = $indexService->portal_category_select(array('status' => 1));
//            foreach ($class_list as $k => $v) {
//                $backarr['portal_categorys'][$v['id']] = $v['name'];
//            }
            $backarr['items'] = $items;
            $this->success("获取成功!", $backarr);
        }

    }

    public function get_f_info()
    {
        $f_id = input('f_id');
        if (!$f_id) {
            $this->error("参数错误");
        }
        $back_arr = [];
        $f_info = Db::name('chat_friends')
            ->where('F_ID', $f_id)
            ->find();
        if (empty($f_info)) {
            $this->error("会话不存在");
        }
        $back_arr['tid'] = $f_info['F_FirendID'];
        $driver_info = Db::name('driver_user')
            ->where('id', $f_info['F_FirendID'])
            ->field('user_name,avatar')
            ->find();
        if (empty($driver_info)) {
            $this->error("司机账号不存在");
        }
        $back_arr['tid_name'] = $driver_info['user_name'] ? $driver_info['user_name'] : '昵称';
        $back_arr['tid_avatar'] = $driver_info['avatar'] ? $driver_info['avatar'] : 'avatar.png';

        $this->success("成功!", $back_arr);
    }
}
